<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>personal</title>
    <!-- 引入Vue.js -->
    <script src="js/vue.min.js"></script>
    <!-- 引入jQuery -->
    <script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
    <style>
        /* CSS 样式 */
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .user-card-container {
            text-align: center;
        }

        .user-card {
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            padding: 20px;
            width: 300px;
        }

        .user-avatar {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            object-fit: cover;
            margin-bottom: 15px;
        }

        .user-name {
            font-size: 1.5em;
            margin-bottom: 10px;
        }

        .score-container {
            display: flex;
            justify-content: space-around;
            font-size: 1.2em;
            margin-top: 20px;
        }

        .score-item {
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .score-label {
            color: #555;
        }

        .score-value {
            color: #333;
            font-weight: bold;
        }
    </style>
</head>
<body>
<div id="app" v-if="user">
    <div class="user-card-container">
        <div class="user-card">
            <a href="http://localhost:8080/boot/changeHead.html"><img :src="'img/head/'+user.head" alt="" class="user-avatar"></a>
            <a href="http://localhost:8080/boot/changePassword.html"><h2 class="user-name">{{ user.studentName }}</h2></a>
            <div class="score-container">
                <div class="score-item">
                    <a href="http://localhost:8080/boot/personScore.html"><span class="score-label">诚信分:</span></a>
                    <span class="score-value">{{ user.lntegrityScore }}</span>
                </div>
                <div class="score-item">
                    <a href="http://localhost:8080/boot/personActivity.html"><span class="score-label">个人分:</span></a>
                    <span class="score-value">{{ user.activityScore }}</span>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    // 创建Vue实例
    new Vue({
        el: '#app',
        data: {
            user: null
        },
        created() {
            // 组件创建时发起请求获取用户信息
            this.fetchUserInfo();
        },
        methods: {
            fetchUserInfo() {
                // 使用jQuery的$.ajax发送AJAX请求
                $.ajax({
                    url: 'personal', // 确保这个URL指向你的后端API
                    type: 'GET',
                    dataType: 'json',
                    success: (response) => {
                        this.user = response; // 将后端返回的数据绑定到Vue实例的数据属性
                    },
                    error: (xhr, status, error) => {
                        console.error('Error fetching user info:', error);
                        alert('无法获取用户信息，请稍后再试。');
                    }
                });
            }
        }
    });
</script>
</body>
</html>